<template>
	<div>
		<el-tabs v-model="activeName" @tab-click="handleTabChange">
			<template v-if="tabsList">
				<el-tab-pane v-for="(item, index) in tabsList" :key="index" :label="item.label" :name="item.name"></el-tab-pane>
			</template>
			<template v-else>
				<el-tab-pane label="基础信息" name="BaseDetail"></el-tab-pane>
				<el-tab-pane label="扩展信息" name="Extend"></el-tab-pane>
				<el-tab-pane label="其他信息" name="Other"></el-tab-pane>
				<el-tab-pane label="视频监控信息" name="VideoMonitor"></el-tab-pane>
				<el-tab-pane label="资料信息" name="information"></el-tab-pane>
				<!-- <el-tab-pane label="运营记录" name="OperateRecord"></el-tab-pane> -->
				<!-- <el-tab-pane label="年审记录" name="AnnualAudit"></el-tab-pane> -->
				<el-tab-pane label="从业人员" name="practitioner"></el-tab-pane>
				<el-tab-pane label="等级评定档案" name="RateAccess"></el-tab-pane>
				<el-tab-pane label="机构服务和管理" name="insteServer"></el-tab-pane>
				<el-tab-pane label="补贴管理" name="subsidyFunds"></el-tab-pane>
				<el-tab-pane label="信息编辑记录" name="DataChangeLog"></el-tab-pane>
				<el-tab-pane label="上链信息" name="ChainBlockInfo"></el-tab-pane>
				<el-tab-pane label="安全监管信息" name="safetyRegulatoryInfo"></el-tab-pane>
			</template>

			<div class="content-card">
				<html-label :title="activeLabelTitle">
					<div v-if="!(nowRowData.dataStatus && nowRowData.dataStatus !== '0') && ['BaseDetail', 'Extend', 'Other'].includes(activeName) && showBtn">
						<!-- <el-button v-auth="[nowRowData.isOperate == 1, baseConfig.auth.edit]" type="primary" plain @click="handleOperate('edit')">
							信息变更
						</el-button> -->
					</div>
				</html-label>
				<component
					:is="whickComm[activeName]"
					:soleKey="`dpServiceOrgBase-${nowRowData.creditCode}`"
					:nowRowData="nowRowData"
					:isWithAuth="0"
					:actionBtn="false"
					:searchConfig="false"
					:ifShowSearch="false"	
					v-bind="customAttrs"	
				></component>
			</div>
		</el-tabs>
	</div>
</template>

<script setup lang="ts">
import BaseDetail from './BaseDetail/index.vue'
import AnnualAudit from './AnnualAudit/index.vue'
import RateAccess from './RateAccess'
import Extend from './Extend/index.vue'
import Other from './Other/index.vue'
import OperateRecord from './OperateRecord/index.vue'
import practitioner from './practitioner/index.vue'
import insteServer from '@/views/datacenter/business/insteServer/index.vue'
import subsidyFunds from './SubsidyManagement/index.vue'
import safetyRegulatoryInfo from './safetyRegulatoryInfo/index.vue'
import DataChangeLog from '@/views/datacenter/components/DataChangeLog/index.vue'
import { baseConfig } from '../../config'
import { useOperate } from '@/views/datacenter/hooks/useConfig'
import { useCommonStore } from '@/stores/common'
import bus from '@/utils/eventbus'
import ChainBlockInfo from './ChainBlockInfo/index.vue'
import information from './information/index.vue'
import VideoMonitor from './VideoMonitor/index.vue'

const { setTempParams, setGloablParams, setMoreSearch } = useCommonStore()
const { onDelete, onMessageChange } = useOperate(2)
// 去除api
let arrts = useAttrs()
const customAttrs = computed(() => {
	const { api, ...rest } = arrts;
	return rest;
})
const whickComm = {
	BaseDetail,
	AnnualAudit,
	RateAccess,
	Extend,
	Other,
	OperateRecord,
	practitioner,
	insteServer,
	subsidyFunds,
	DataChangeLog,
	ChainBlockInfo,
	information,
	VideoMonitor,
	safetyRegulatoryInfo
}
const activeName = ref('BaseDetail')
type Props = {
	nowRowData?: any
	showBtn?: boolean
	tabsList?: any
}

const props = withDefaults(defineProps<Props>(), {
	showBtn: true,
})
provide('nowRowData', props.nowRowData)

setMoreSearch({
	params: {
		creditCode: props.nowRowData.creditCode,
	},
})

const emit = defineEmits(['refresh', 'rechange'])
const activeLabelTitle = ref('基本信息')
const openEdit = () => {
	onMessageChange().then(() => {
		const activeStr = {
			BaseDetail: 1,
			Extend: 2,
			Other: 3,
		}
		setTempParams({
			name: props.nowRowData.organizationName,
			organizationName: props.nowRowData.organizationName,
			creditCode: props.nowRowData.creditCode,
			active: activeStr[activeName.value] || 1,
		})
		emit('rechange', 'Rechange', props.nowRowData, '信息变更数据')
	})
}

const handleOperate = (type) => {
	if (type == 'delete') {
		onDelete(props.nowRowData[baseConfig.rowKey], baseConfig.api.delete, props.nowRowData.organizationName)
			.then(() => {
				emit('refresh')
				setMoreSearch({})
				setGloablParams({})
			})
			.catch(() => {
				return
			})
		return
	}
	openEdit()
}

const handleTabChange = (tab) => {
	activeLabelTitle.value = tab.props.label
	setMoreSearch({
		params: {
			creditCode: props.nowRowData.creditCode,
		},
	})
	setGloablParams({
		creditCode: props.nowRowData.creditCode,
	})
}
bus.on('menu-operate', (res) => {
	if (res.pageName == baseConfig.pageName) {
		handleOperate(res.operate)
	}
})

onUnmounted(() => {
	setMoreSearch({})
	setGloablParams({})
})
</script>

<style scoped></style>
